﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Controls;
using Microsoft.Samples.ServiceHosting.StorageClient;
using System.Windows.Media.Imaging;
using System.Windows.Media;

namespace BlobExplorer
{
    public class AccessControlToImageConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (targetType == typeof(ImageSource) && typeof(BlobContainer).IsAssignableFrom(value.GetType()))
            {
                string source = null;

                if (((BlobContainer)value).GetContainerAccessControl() == ContainerAccessControl.Private)
                {
                    source = "privcontainer.jpg";
                }
                else
                {
                    source = "pubcontainer.jpg";
                }

                BitmapImage img = new BitmapImage(new Uri(source, UriKind.Relative));

                return img;
            }

            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
